package com.zego.wawaji.wawaji_client;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.base.observer.PActivityLifecycleCallbacks;
import com.zego.wawaji.ui.view.adDialog.utils.DisplayUtil;

/**
 * 热修复: Application代理类
 * Created by Su on 2018/3/26.
 */
public class AppTinkerLike extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // ============= 自有功能 =========================
        init();
    }


    // ======================================== 自有功能 =====================================
    public static Context context;
    public static Activity activity;
    private static PActivityLifecycleCallbacks lifecycleCallbacks;
    public static long t;  // 记录应用启动时间
    public static String cookie = "";
    public static boolean isLogin = false;
    public static long uid = 0;//全局uid，避免重复从本地获取
    public static boolean isNewUser = false; // 是否是新用户

    private void init() {
        context = getApplicationContext();
        t = System.currentTimeMillis();
        lifecycleCallbacks = new PActivityLifecycleCallbacks();
        ModuleMgr.initModule(context);
        DisplayUtil.initDisplayOpinion(context);
        MultiDex.install(context);

        lifecycleCallbacks = new PActivityLifecycleCallbacks();
        registerActivityLifecycleCallbacks(lifecycleCallbacks);

//        Bugtags.start("a36791712e3b13c5583889dc09ba0459", getApplicationContext(), Bugtags.BTGInvocationEventNone);

        // LeakCanary
//        if (!LeakCanary.isInAnalyzerProcess(this)) {
//            LeakCanary.install(this);
//        }
    }

    public static Context getContext() {
        return context;
    }

    /**
     * @return 获取当前展示的activity对象，如果activity为null则返回applicationContext
     */
    public static Activity getActivity() {
        return activity == null ? (Activity) context : activity;
    }
}
